package com.bytz.modules.cms.statistic.enums;

import java.time.temporal.ChronoUnit;

public enum IntervalType {
    //年
    YEARS("年", ChronoUnit.YEARS, 1),
    //半年
    HALF_YEARS("半年", ChronoUnit.MONTHS, 6),
    //季度
    QUARTERS("季度", ChronoUnit.MONTHS, 3),
    //月
    MONTHS("月", ChronoUnit.MONTHS, 1),
    //周
    WEEKS("周", ChronoUnit.WEEKS, 1),
    //日
    DAYS("天", ChronoUnit.DAYS, 1),
    ;
    private final String chineseName;

    private final ChronoUnit chronoUnit;

    private final Integer time;


    IntervalType(String chineseName, ChronoUnit chronoUnit, Integer time) {
        this.chineseName = chineseName;
        this.chronoUnit = chronoUnit;
        this.time = time;
    }

    public ChronoUnit getChronUnit() {
        return chronoUnit;
    }

    public Integer getTime() {
        return time;
    }

    public String getChineseName() {
        return chineseName;
    }

    public static IntervalType operatorOf(String key) {

        if (key == null) {
            return null;
        }

        for (IntervalType type : IntervalType.values()) {
            if (type.name().equals(key)) {
                return type;
            }
        }

        return null;
    }
}

